import { View } from "../../../mvc/core/View";
import { MarketOneConfig } from "../../resource/MarketOneConfig";
import { MarketTwoConfig } from "../../resource/MarketTwoConfig";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { MarketTabBar } from "./MarketTabBar";
import { EventName } from "../../mvc/EventName";
import { GScrollPane } from "../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { DataEvent } from "../../events/DataEvent";
import { Cache } from "../../cache/Cache";
import { SearchConditionData } from "./SearchConditionData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { HotSellInfo } from "./HotSellInfo";
type int = number;
//class SearchTypeList
    
    export  class SearchTypeList extends View
    {
        constructor()
        {
            super();
            this._codesMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._firstSellInfoTagDp = [];
            this._secondSellInfoTagDp = [];
            this._firstSeekInfoTagDp = [];
            this._secondSeekInfoTagDp = [];
            this.initDp();
            this.init();
            return;
        }

        public get eggData(): Object
        {
            return this._eggData;
        }

        public get codesMap(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._codesMap;
        }

        public set codesMap(arg1: Map<any, any> /* flash.utils.Dictionary */)
        {
            this._codesMap = arg1;
            return;
        }

        /* internal  */initDp(): void
        {
            var loc1=MarketOneConfig.instance.firstSellInfoTagMap;
            var loc2=MarketTwoConfig.instance.secondSellInfoTagMap;
            this.setDp(loc1, loc2, this._firstSellInfoTagDp, this._secondSellInfoTagDp);
            var loc3=MarketOneConfig.instance.firstSeekBuyInfoTagMap;
            var loc4=MarketTwoConfig.instance.secondSeekInfoTagMap;
            this.setDp(loc3, loc4, this._firstSeekInfoTagDp, this._secondSeekInfoTagDp);
            return;
        }

        /* internal  */setDp(arg1: Map<any, any> /* flash.utils.Dictionary */, arg2: Map<any, any> /* flash.utils.Dictionary */, arg3: Array<any>, arg4: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=arg1;
            for(loc1 of loc5) 
            {
                arg3.push({"name": loc1.oneName, "id": loc1.oneId});
                loc3 = new Array<any>();
                var loc6=0;
                var loc7=arg2;
                for(loc2 of loc7) 
                {
                    if (loc1.oneId != loc2.oneId) 
                    {
                        continue;
                    }
                    loc3.push({"color": 16777215, "text": loc2.twoName, "id": loc2.twoId});
                }
                loc3.sortOn("id", Array.NUMERIC);
                arg4.push(loc3);
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ObjCreate.createBg(0, 0, 143, 370, this);
            var loc2=ObjCreate.createBg(-1, -3, 148, 30, this, ImagesConst.RbListHeader);
            var loc3=ObjCreate.createTextField(Language.getString(31049), 30, 5, 80, 25, this, new GTextFormat("", 14, 16571138));
            this._marketTabBar = new MarketTabBar();
            this._marketTabBar.firstTagDp = this._firstSellInfoTagDp;
            this._marketTabBar.secondTagDp = this._secondSellInfoTagDp;
            this._marketTabBar.addEventListener(EventName.MarketSearchTypeChange, this.onSearchTypeChangeHandler);
            this._marketTabBar.addEventListener(EventName.MarketButtonClose, this.onButtonCloseHandler);
            this._marketTabBar.addEventListener(EventName.RankBarInitEnd, this.onRankBarInitEndHandler);
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = 5;
            this._scrollPane.y = 30;
            this._scrollPane.width = 140;
            this._scrollPane.height = 330;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.source = this._marketTabBar;
            this._scrollPane.scrollDrag = false;
            this._scrollPane.setScrollBarSize(19);
            addChild(this._scrollPane);
            this._scrollPane.update();
            return;
        }

        /* internal  */onSearchTypeChangeHandler(arg1: DataEvent): void
        {
            var loc4=null;
            var loc1=arg1.data;
            var loc2=(loc1.oneIndex as int) + 1;
            var loc3=(loc1.twoIndex as int) + 1;
            if (this._marketType != 0) 
            {
                if (this._marketType == 1) 
                {
                    loc2 = this._firstSellInfoTagDp.length + loc2;
                    loc4 = MarketTwoConfig.instance.getMarketTwoSeekInfo(loc2, loc3);
                }
            }
            else 
            {
                loc4 = MarketTwoConfig.instance.getMarketTwoSellInfo(loc2, loc3);
            }
            var loc5=-1;
            if (loc4) 
            {
                if (loc2 == 9 && loc4.color > 0) 
                {
                    loc5 = loc4.color;
                }
                this._eggData = {"eggColor": loc5};
                this._codesMap = Cache.instance.market.getCodesInMarket(loc2, loc3, loc4.career);
            }
            else 
            {
                this._eggData = null;
            }
            SearchConditionData.codesMap = this._codesMap;
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSearch, this._eggData));
            return;
        }

        /* internal  */onButtonCloseHandler(arg1: Object /* flash.events.Event */): void
        {
            this._scrollPane.update();
            this._scrollPane.drawNow();
            this._codesMap = new Map<any, any> /* flash.utils.Dictionary */();
            SearchConditionData.codesMap = this._codesMap;
            return;
        }

        /* internal  */onRankBarInitEndHandler(arg1: Object /* flash.events.Event */): void
        {
            this._scrollPane.update();
            this._scrollPane.drawNow();
            if (!(this._oneIdx == -1) && !(this._twoIdx == -1)) 
            {
                this._marketTabBar.setTabBar(this._oneIdx, this._twoIdx);
                this._oneIdx = -1;
                this._twoIdx = -1;
            }
            return;
        }

        public reset(): void
        {
            this._codesMap = new Map<any, any> /* flash.utils.Dictionary */();
            SearchConditionData.codesMap = this._codesMap;
            this._marketTabBar.reset();
            return;
        }

        public setMarketTabBarSell(arg1: int, arg2: int): void
        {
            this._oneIdx = arg1;
            this._twoIdx = arg2;
            this._marketTabBar.setTabBar(arg1, arg2);
            return;
        }

        public setHotMarketTabBarSell(arg1: HotSellInfo): void
        {
            this._oneIdx = arg1.oneIndex;
            this._twoIdx = arg1.twoIndex;
            this._marketTabBar.setTabBar(arg1.oneIndex, arg1.twoIndex);
            return;
        }

        public setTagBar(arg1: int): void
        {
            this._marketType = arg1;
            this.reset();
            if (arg1 != 0) 
            {
                if (arg1 == 1) 
                {
                    this._marketTabBar.firstTagDp = this._firstSeekInfoTagDp;
                    this._marketTabBar.secondTagDp = this._secondSeekInfoTagDp;
                }
            }
            else 
            {
                this._marketTabBar.firstTagDp = this._firstSellInfoTagDp;
                this._marketTabBar.secondTagDp = this._secondSellInfoTagDp;
            }
            return;
        }

        /* internal */ /* var */_codesMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_marketTabBar: MarketTabBar;

        /* internal */ /* var */_firstSellInfoTagDp: Array<any>;

        /* internal */ /* var */_secondSellInfoTagDp: Array<any>;

        /* internal */ /* var */_firstSeekInfoTagDp: Array<any>;

        /* internal */ /* var */_secondSeekInfoTagDp: Array<any>;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_marketType: int;

        /* internal */ /* var */_eggData: Object;

        /* internal */ /* var */_oneIdx: int=-1;

        /* internal */ /* var */_twoIdx: int=-1;
    }
